package datasv.courseProduce_datasv;

import po.CoursePublishPO;
import resultmessage.CourseProduceRM;
import data.datafactory.DatabaseOperator;

public class UpdateCoursePublish {
	public static void main(String[] args) {
		System.out.println(new UpdateCoursePublish()
				.updateCoursePublish(new CoursePublishPO("00101130040",
						"test.t.t.t", "hege", "xian 2")));
	}

	public CourseProduceRM updateCoursePublish(CoursePublishPO po) {
		return addInSql(po);
	}

	private CourseProduceRM addInSql(CoursePublishPO po) {
		String collegeID = po.getCollegeID();
		DatabaseOperator op = new DatabaseOperator("college" + collegeID);
		if (!op.ifDatabaseExist()
				|| !op.ifIDExist("course_list", po.getCourseID())) {
			return CourseProduceRM.COURSE_ID_NOT_EXSIT;
		}
		int num = AddCoursePublish.columnNum;
		String[][] info = new String[num][2];
		info[0][0] = AddCoursePublish.columnName[0];
		info[0][1] = po.getCourseID();
		info[1][0] = AddCoursePublish.columnName[1];
		info[1][1] = po.getTeacher();
		info[2][1] = po.getTime();
		info[2][0] = AddCoursePublish.columnName[2];
		info[3][1] = po.getLocation();
		info[3][0] = AddCoursePublish.columnName[3];

		for (int i = 0; i < num; i++) {
			if (!op.setOneInform(info[0][1], info[i][1], "course_list",
					info[i][0])) {
				return CourseProduceRM.COURSEPUBLISH_NOT_EXSIT;
			}
		}
		return CourseProduceRM.SUCCESS;
	}
}
